package com.boot.export.files;

import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;

import java.io.File;
import java.io.FileFilter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GetAllFileForSuffix {
    public static List<File> operation(File file) {
        List<File> allFiles = new ArrayList<>();
        String[] suffix = {".wav", ".mp3"};

        FileFilter fileFilter = new SuffixFileFilter(suffix);
        List<File> files = Arrays.asList(file.listFiles(fileFilter));
        System.out.println("A");
        files.forEach(file1 -> System.out.println(file1.getPath()));
        allFiles.addAll(files);

        //获取全部文件夹路径
        File[] files1 = file.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);
        for (File file1 : files1) {
            List<File> operation = operation(file1);
            allFiles.addAll(operation);
        }

        return allFiles;
    }

    public static void main(String[] args) {
        String path = "G:\\test";
        File file = new File(path);
        List<File> operation = operation(file);
    }
}
